package com.rmondjone.face.ViewModel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.ant.http.HttpManager
import com.rmondjone.androidcamerademo.CommonService
import com.rmondjone.androidcamerademo.FileBean
import com.rmondjone.androidcamerademo.bean.CameraType
import com.rmondjone.androidcamerademo.bean.FaceConsultBean

/**
 * copyright：
 * @author：anthui creation date： .
 * @since: 1.0.0
 * @describe:
 */
class FaceViewModel : ViewModel() {

    //加载完成
    val isLoadErr = MutableLiveData<String>()
    val isLoadFinish = MutableLiveData<Boolean>()


    val faceConsultBean = MutableLiveData<FaceConsultBean>()


    var filePath = ""

    fun getData(path: String, type: Int) {
        filePath = path
        FileViewModel().upFile(path, object : OnCallBack<FileBean>() {
            override fun onSuccess(item: FileBean) {


                if (type == CameraType.CAMERA_TYPE_FMIAN_ZHEN) {

                    loadMianZhen(item)
                } else {
                    loadSheZhen(item)
                }
            }

            override fun onFailure(code: Int, msg: String?, er: Throwable?) {
                isLoadErr.value = msg ?: "网络不稳当"
            }

        })
    }


    fun loadMianZhen(item: FileBean) {
        HttpManager.getService(CommonService::class.java).acupoint(item.full_url
                ?: "").enqueue(object : OnCallBack<FaceConsultBean>() {
            override fun onSuccess(item: FaceConsultBean) {
                faceConsultBean.value = item
                isLoadFinish.value = true

            }

            override fun onFailure(code: Int, msg: String?, er: Throwable?) {
                isLoadErr.value = msg ?: "网络不稳当"


            }

        })
    }

    fun loadSheZhen(item: FileBean) {
        HttpManager.getService(CommonService::class.java).tongue(item.full_url
                ?: "").enqueue(object : OnCallBack<FaceConsultBean>() {
            override fun onSuccess(item: FaceConsultBean) {
                faceConsultBean.value = item
                isLoadFinish.value = true


            }

            override fun onFailure(code: Int, msg: String?, er: Throwable?) {
                er?.printStackTrace()
                isLoadErr.value = msg ?: "网络不稳当"

            }

        })
    }

}